package com.fengplus.demo.hander;

import com.fengplus.demo.entity.CommonResult;
import com.fengplus.demo.entity.ExceptionResult;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@RestControllerAdvice
public class ExceptionHannder {

//    @ExceptionHandler({ArithmeticException.class, NullPointerException.class})
    @ExceptionHandler({RuntimeException.class})
    public CommonResult handleRuntimeException(Exception e) {
        return new CommonResult(500, e.getMessage());
    }

    @ExceptionHandler({ExceptionResult.class})
    public CommonResult handleResultException(ExceptionResult e) {
        return new CommonResult(e.getCode(), e.getMsg());
    }

}
